/*
 */

package com.railway.system.dao.impl;
import org.springframework.stereotype.Repository;

import java.util.*;

import org.apache.commons.lang.StringUtils;

import com.railway.common.base.*;
import com.railway.common.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.railway.system.dao.*;
import com.railway.system.model.*;
import com.railway.system.service.*;
import com.railway.system.vo.query.*;

/**
 * @author  jiangcheng
 * @version 1.0
 * @since 1.0
 */




@Repository("sysUserDao")
public class SysUserDaoImpl extends BaseIbatisDao<SysUser,java.lang.String> implements ISysUserDao{
	
	@Override
	public String getIbatisSqlMapNamespace() {
		return "SysUser";
	}
	
	public SysUser getById(java.lang.String id){
		return super.getById( id);
	}
	
	public void deleteById(java.lang.String id){
		super.deleteById(id);
	}
	
	/** 插入数据 */
	public String saveUser(SysUser entity){
		String Id=IdGenerator.genUUIDStr();
		if(StringUtils.isEmpty(entity.getId())) {
			entity.setId(Id);
		}
		 super.save(entity);
		 return Id;
	}
	
	/** 更新数据 */
	public void update(SysUser entity){
		super.update(entity);
	}

	public boolean isUnique(SysUser entity, String uniquePropertyNames){
		return super.isUnique( entity, uniquePropertyNames);
	}
	
	public List<SysUser> findAll(){
		
		return getSqlMapClientTemplate().queryForList("SysUser.findPage");
	}
	
	public void saveOrUpdate(SysUser entity) {
		if(StringUtils.isEmpty(entity.getId())) {
			entity.setId(IdGenerator.genUUIDStr());
			super.save(entity);
		}
		else 
			super.update(entity);
	}
	
	public Page findPage(SysUserQuery query) {
		return pageQuery("SysUser.findPage",query);
	}
	public List getUsers(SysUserQuery query) {
	     List r= getSqlMapClientTemplate().queryForList("SysUser.findPage",query);
		 return r;
	}
	
	public List getUsersByDeptId(String deptid) {
		try{
         Map map = new HashMap();
         map.put("deptId", deptid);
		 List r= getSqlMapClientTemplate().queryForList("SysUser.getUsersByDeptId",map);
		 return r;
	}catch(Exception e){
		e.printStackTrace();
	}
		return null;
	}
}
